package cn.com.cfae.iras.doc.analyze.components.consistency;

import cn.com.cfae.iras.doc.analyze.components.BaseComponent;
import cn.com.cfae.iras.doc.analyze.components.beans.ComponentResult;
import cn.com.cfae.iras.doc.analyze.parse.kv.KVText;
import cn.com.cfae.iras.doc.analyze.parse.kv.TextLayout;
import cn.com.cfae.iras.doc.analyze.parse.model.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.xml.soap.Text;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by zouxun on 2018/10/29
 */
@Component("U1011")
@Scope("prototype")
public class U1011 extends BaseComponent {
    private static Logger logger = LoggerFactory.getLogger(U1011.class);

    @Autowired
    U1004 u1004;

    /**
     * @desc 核对在治理结构部分（M-5-6）中表述的股东大会和董事会人数是否和企业人员基本情况部分（M-5-7）董事、监事列表中的人数一致
     * 1、从文本中抽取董事会、监事会、高管（总经理）人数；
     * 2、从表格中抽取董事会、监事会、高管人数；
     * 3、两者数据进行一致性比较；
     * 4、不存在进行提示；
     * @return
     */
    @Override
    public List<ComponentResult> handlerM() {
        logger.info("开始调用U1011组件,处理M表.................");
        String m57ChapterId="M-5-7";
        List<ComponentResult> componentResults = ruleCheck(m57ChapterId);
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerBM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerDM() {
        logger.info("开始调用U1011组件,处理DM表.................");
        String m57ChapterId="DM-5-7";
        List<ComponentResult> componentResults = ruleCheck(m57ChapterId);
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerBDM() {
        return null;
    }


    private TextLayout getTextLayout(List<Map<String,ExtractItem>> extractItemList,String zwType,boolean flag){
        if(CollectionUtils.isNotEmpty(extractItemList)){
            for(Map<String,ExtractItem> extractItemMap:extractItemList){
                ExtractItem zwExtractItem = extractItemMap.get("ZW");
                if(zwExtractItem!=null) {
                    KVText zwKvTextValue = zwExtractItem.getValue();
                    if (zwKvTextValue != null) {
                        String zwText = zwKvTextValue.getText();

                        if(StringUtils.isNotEmpty(zwText)){
                            if(flag){
                                if(zwText.contains("董事") || zwText.contains("监事")){
                                    continue;
                                }
                            }
                            if(zwText.contains(zwType)){
                                if(zwKvTextValue.getTextLayout()!=null){
                                    return zwKvTextValue.getTextLayout();
                                }
                            }

                        }

                    }
                }
            }
        }
        return null;
    }

    private TextLayout getSectionTitlePosition(List<SectionModel> sectionModelList,String type){
        TextLayout textLayout = null;

        if(CollectionUtils.isNotEmpty(sectionModelList)){
            top:for(SectionModel sectionModel:sectionModelList){
                String sectionModelTitle = sectionModel.getTitle();
                if(StringUtils.isNotEmpty(sectionModelTitle)){
                    if(sectionModelTitle.contains("董事") || sectionModelTitle.contains("监事") || sectionModelTitle.contains("员工情况") || sectionModelTitle.contains("人员情况") || sectionModelTitle.contains("员工基本情况") || sectionModelTitle.contains("人员基本情况")){
                        List<SectionModel> childSectionModelList = sectionModel.getChildSectionModelList();

                        if(CollectionUtils.isNotEmpty(childSectionModelList)){
                            for(SectionModel childSectionModel:childSectionModelList){
                                String childSectionModelTitle = childSectionModel.getTitle();
                                if(StringUtils.isNotEmpty(childSectionModelTitle)){
                                    if(type.equals("董事")){
                                        if(childSectionModelTitle.contains("员工情况") || childSectionModelTitle.contains("人员情况") || childSectionModelTitle.contains("员工基本情况") || childSectionModelTitle.contains("人员基本情况") || childSectionModelTitle.contains("董事、监事") || childSectionModelTitle.contains("董事会情况") || childSectionModelTitle.contains("董事情况") || childSectionModelTitle.contains("董事会成员")){
                                            textLayout = childSectionModel.getTextLayout();
                                            break top;
                                        }
                                    }else if(type.equals("监事")){
                                        if(childSectionModelTitle.contains("员工情况") || childSectionModelTitle.contains("人员情况") || childSectionModelTitle.contains("员工基本情况") || childSectionModelTitle.contains("人员基本情况") || childSectionModelTitle.contains("董事、监事") || childSectionModelTitle.contains("监事会情况") || childSectionModelTitle.contains("监事情况") || childSectionModelTitle.contains("监事会成员")){
                                            textLayout = childSectionModel.getTextLayout();
                                            break top;
                                        }
                                    }else if(type.equals("高管")){
                                        if(childSectionModelTitle.contains("员工情况") || childSectionModelTitle.contains("人员情况") || childSectionModelTitle.contains("员工基本情况") || childSectionModelTitle.contains("人员基本情况") || childSectionModelTitle.contains("高管人员") || childSectionModelTitle.contains("高级管理人员") || childSectionModelTitle.contains("高级管理人员情况")){
                                            textLayout = childSectionModel.getTextLayout();
                                            break top;
                                        }
                                    }
                                }
                            }
                        }

                        if(textLayout==null){
                            textLayout = sectionModel.getTextLayout();
                            break top;
                        }

                    }
                }
            }
        }
        return textLayout;
    }


    private Integer getStatisticalNumber(List<Map<String,ExtractItem>> extractItemList,String position,String[] strArray){
        int result = 0;

        //计数
        int count = 0;

        if(CollectionUtils.isNotEmpty(extractItemList)){
            if(position.equals("监事")){
                for(Map<String,ExtractItem> extractItemMap:extractItemList) {
                    ExtractItem extractItem = extractItemMap.get("ZW");
                    if(extractItem!=null){
                        KVText kvText = extractItem.getValue();
                        if(kvText!=null){
                            if(StringUtils.isNotEmpty(kvText.getText())){
                                if(kvText.getText().contains("监事")){
                                    count++;
                                }
                            }
                        }
                    }
                }

                result = count;
            }else{
                Boolean flag = true;

                ExtractItem xmTempExtractItem = extractItemList.get(0).get("XM");
                if(xmTempExtractItem!=null){
                    KVText xmKvTextValue = xmTempExtractItem.getValue();
                    if(xmKvTextValue!=null){
                        if(StringUtils.isNotEmpty(xmKvTextValue.getText())){
                            flag = false;
                        }
                    }
                }

                if(!flag){
                    for(Map<String,ExtractItem> extractItemMap:extractItemList){
                        ExtractItem xmExtractItem = extractItemMap.get("XM");
                        if(xmExtractItem!=null){
                            KVText kvTextValue = xmExtractItem.getValue();
                            if(kvTextValue!=null){
                                String xmText = kvTextValue.getText();
                                if(StringUtils.isNotEmpty(xmText)){
                                    if(xmText.equals("男") || xmText.equals("女")){
                                        flag=true;
                                    }
                                }
                            }
                        }
                    }
                }

                if(!flag){
                    Map<String,String> xmMap = new HashMap<>();

                    List<String> doubleNameList = new ArrayList<>();

                    for(Map<String,ExtractItem> extractItemMap:extractItemList) {
                        ExtractItem zwExtractItem = extractItemMap.get("ZW");
                        ExtractItem xmExtractItem = extractItemMap.get("XM");

                        if(xmExtractItem!=null){
                            KVText xmKvText = xmExtractItem.getValue();
                            if(xmKvText!=null){
                                String xmText = xmKvText.getText();
                                if(StringUtils.isNotEmpty(xmText)){
                                    xmText = xmText.replaceAll("\\s{1,}","");

                                    if(zwExtractItem!=null){
                                        KVText zwKvText = zwExtractItem.getValue();
                                        if(StringUtils.isNotEmpty(zwKvText.getText())){
                                            String zwText = zwKvText.getText().replaceAll("\\s{1,}","");

                                            if(xmMap.containsKey(xmText)){
                                                if(xmMap.get(xmText).equals("监事")){
                                                    xmMap.put(xmText,zwText);
                                                    continue;
                                                }
//                                                if(xmText.equals("男") || xmText.equals("女")){
//                                                    continue;
//                                                }
                                                doubleNameList.add(xmText);
                                            }else{
                                                xmMap.put(xmText,zwText);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Set<String> xmSet = xmMap.keySet();

                    if(CollectionUtils.isNotEmpty(doubleNameList)){
                        xmSet.removeAll(doubleNameList);
                    }

                    if(position.equals("董事")){
                        if(xmSet.size()>0){
                            for(String xm:xmSet){
                                if(xmMap.get(xm).contains("董事")){
                                    if(!xmMap.get(xm).contains("秘书")){
                                        count++;
                                    }
                                }
                            }
                        }

                        if(CollectionUtils.isNotEmpty(doubleNameList)){
                            result=doubleNameList.size() + count;
                        }else{
                            result=count;
                        }

                    }else if(position.equals("高管")){
                        if(xmSet.size()>0){
                            for(String xm:xmSet){
                                if(!xmMap.get(xm).contains("董事")){
                                    if(!xmMap.get(xm).contains("监事")){
                                        count++;
                                    }
                                }else{
                                    if(xmMap.get(xm).contains("秘书")){
                                        count++;
                                    }
                                }
                            }
                        }
                        result = count+doubleNameList.size();
                    }
                }else{
                    for(Map<String,ExtractItem> extractItemMap:extractItemList) {
                        ExtractItem zwExtractItem = extractItemMap.get("ZW");
//                    ExtractItem xmExtractItem = extractItemMap.get("XM");

                        if(zwExtractItem!=null){
                            KVText zwKvTextValue = zwExtractItem.getValue();

                            if(zwKvTextValue!=null){
                                String zw = zwKvTextValue.getText();

                                if(StringUtils.isNotEmpty(zw)){
                                    zw=zw.replaceAll("\\s{1,}","");

                                    if(position.equals("董事")){
                                        if(zw.contains("董事")){
                                            if(zw.contains("秘书")) continue;
                                            count++;
                                        }
                                    }else if(position.equals("高管")){
                                        if(!zw.contains("董事")){
                                            if(!zw.contains("监事")){
                                                count++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    result = count;
                }


            }

        }

        return result;
    }



    private List<ComponentResult> ruleCheck(String m57ChapterId){
        DocumentModel documentModel = super.getExtractData();

        List<ComponentResult> componentResults = new ArrayList<>();

        ComponentResult componentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"核对在治理结构部分中表述的股东大会和董事会人数是否和企业人员基本情况部分董事、监事列表中的人数一致","",true,getRegulationId(),3,null,"03");

        ChapterModel chapterModel=documentModel.getChapterModel(getCatalogId());

        try{
            if(chapterModel!=null){
                List<SectionModel> sectionModelList=chapterModel.getSectionModelList();

                componentResult.setPageNum(chapterModel.getStartPage());

                ExtractBizModel extractBizModel = chapterModel.getModel("DJG");

                KVText gjglKvTextValue=getKVTextValue(getCatalogId(),"GG","GG");
                KVText jshKvTextValue=getKVTextValue(getCatalogId(),"JSH","JSH");
                KVText dshKvTextValue=getKVTextValue(getCatalogId(),"DSH","DSH");

                //M-5-7企业基本人员情况
                int m57Dsh = 0;//董事会
                int m57Jsh = 0;//监事会
                int m57Gjgl = 0;//高级管理

                List<Map<String,ExtractItem>> extractItemList = null;

                if(extractBizModel!=null){
                    extractItemList = extractBizModel.getTables3();

                    String[] dsArray = new String[]{"秘书"};
                    m57Dsh = getStatisticalNumber(extractItemList,"董事",dsArray);
                    logger.info("M-5-7 企业基本情况董事总人数：{}",m57Dsh);
                    m57Jsh = getStatisticalNumber(extractItemList,"监事",null);
                    logger.info("M-5-7 企业基本情况监事总人数：{}",m57Jsh);
                    String[] ggArray = new String[]{"董事","监事"};
                    m57Gjgl = getStatisticalNumber(extractItemList,"高管",ggArray);
                    logger.info("M-5-7 企业基本情况高管总人数：{}",m57Gjgl);
                }

                logger.info("M-5-7企业人员基本情况：董事会人数:{},监事会人数:{},高级管理人员:{}",m57Dsh,m57Jsh,m57Gjgl);

                //M-5-6 董事会、监事会、高级管理人员人数
                int m56Dsh = 0;
                int m56Jsh = 0;
                int m56GJgl = 0;

                //M-5-6 董事会
                if(dshKvTextValue!=null){
                    String dshText = dshKvTextValue.getText();
                    logger.info("M-5-6治理结构 董事会人数：{}",dshText);
                    if(StringUtils.isNotEmpty(dshText)){
                        m56Dsh = getNumber(dshText);
                    }
                }

                //M-5-6 监事会
                if(jshKvTextValue!=null){
                    String jshText = jshKvTextValue.getText();
                    logger.info("M-5-6治理结构 监事会人数：{}",jshText);
                    if(StringUtils.isNotEmpty(jshText)){
                        m56Jsh = getNumber(jshText);
                    }
                }

                //M-5-6 高级管理
                if(gjglKvTextValue!=null){
                    String gjglText = gjglKvTextValue.getText();
                    logger.info("M-5-6治理结构 高管人数：{}",gjglText);
                    if(StringUtils.isNotEmpty(gjglText)){
                        m56GJgl = getNumber(gjglText);
                    }
                }
                logger.info("M-5-6内部治理情况：董事会人数:{},监事会人数:{},高级管理人员:{}",m56Dsh,m56Jsh,m56GJgl);

                //不一致
                int inconformityCount = 0;
                //一致
                int consistentCount = 0;
                //未识别或无法确定
                int unidentification=0;

                ComponentResult dshComponentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),getChapterId().concat("治理结构董事总人数对比").concat(m57ChapterId).concat("企业人员基本情况董事总人数"),"",true,getRegulationId(),chapterModel.getStartPage(),null,"03");

                TextLayout dshTextLayout = getTextLayout(extractItemList,"董事",false)!=null?getTextLayout(extractItemList,"董事",false):getSectionTitlePosition(sectionModelList,"董事");

                if(dshTextLayout!=null){
                    List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                    ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                    dshComponentResult.setPageNum(dshTextLayout.getPageNumber());
                    textPosition.setX(dshTextLayout.getLeft());
                    textPosition.setY(dshTextLayout.getTop());
                    textPosition.setContent(dshTextLayout.getText());
                    textPositionList.add(textPosition);
                    dshComponentResult.setTextPosition(textPositionList);
                }

                if(m56Dsh!=0 && m57Dsh!=0){
                    String dshDesc = getChapterId().concat("治理结构董事总人数：").concat(String.valueOf(m56Dsh)).concat("，").concat(m57ChapterId).concat("企业人员基本情况董事总人数：").concat(String.valueOf(m57Dsh));
                    logger.info("desc：{}",dshDesc);

                    if(m56Dsh == m57Dsh){
                        logger.info("董事会对比一致");
                        dshComponentResult.setPromptMessage("对比一致，".concat(dshDesc));
                        dshComponentResult.setAnnotationFlag(false);
                        consistentCount++;
                    }else{
                        logger.info("董事会对比不一致");
                        dshComponentResult.setPromptMessage("对比不一致，".concat(dshDesc));
                        inconformityCount++;
                    }
                    componentResults.add(dshComponentResult);
                }else if(m56Dsh==0 && m57Dsh!=0){
                    unidentification++;
                    dshComponentResult.setPromptMessage("未识别".concat(getChapterId()).concat("治理结构董事总人数，").concat("已识别").concat(m57ChapterId).concat("企业人员基本情况董事总人数：").concat(String.valueOf(m57Dsh)).concat("，建议人工核对"));
                    componentResults.add(dshComponentResult);
                }else if(m56Dsh!=0 && m57Dsh==0){
                    unidentification++;
                    dshComponentResult.setPromptMessage("未识别".concat(m57ChapterId).concat("企业人员基本情况董事总人数，").concat("已识别").concat(getChapterId()).concat("治理结构董事总人数：").concat(String.valueOf(m56Dsh)).concat("，建议人工核对"));
//                    List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
//                    ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
//                    if(dshKvTextValue!=null){
//                        TextLayout textLayout = dshKvTextValue.getTextLayout();
//                        if(textLayout!=null){
//                            textLayout.setLeft(textLayout.getLeft());
//                            textLayout.setTop(textLayout.getTop());
//                            textLayout.setText(textLayout.getText());
//                            dshComponentResult.setPageNum(textLayout.getPageNumber());
//                            textPositionList.add(textPosition);
//                        }
//                    }
//                    dshComponentResult.setTextPosition(textPositionList);
                    componentResults.add(dshComponentResult);
                }else if(m56Dsh==0 && m57Dsh==0){
                    unidentification++;
                    dshComponentResult.setPromptMessage("未识别".concat(getChapterId()).concat("治理结构董事总人数，").concat("未识别").concat(m57ChapterId).concat("企业人员基本情况董事总人数").concat("，建议人工核对"));
                    componentResults.add(dshComponentResult);
                }

                ComponentResult jshComponentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),getChapterId().concat("治理结构监事总人数对比").concat(m57ChapterId).concat("企业人员基本情况监事总人数"),"",true,getRegulationId(),chapterModel.getStartPage(),null,"03");

                TextLayout jshTextLayout = getTextLayout(extractItemList,"监事",false)!=null?getTextLayout(extractItemList,"监事",false):getSectionTitlePosition(sectionModelList,"监事");

                if(jshTextLayout!=null){
                    List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                    ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                    textPosition.setX(jshTextLayout.getLeft());
                    textPosition.setY(jshTextLayout.getTop());
                    textPosition.setContent(jshTextLayout.getText());
                    textPositionList.add(textPosition);
                    jshComponentResult.setTextPosition(textPositionList);
                    jshComponentResult.setPageNum(jshTextLayout.getPageNumber());
                }

                if(m56Jsh!=0 && m57Jsh!=0){
                    String jshDesc = getChapterId().concat("治理结构监事总人数：").concat(String.valueOf(m56Jsh)).concat("，").concat(m57ChapterId).concat("企业人员基本情况监事总人数：").concat(String.valueOf(m57Jsh));
                    logger.info("desc：{}",jshDesc);
                    if(m56Jsh == m57Jsh){
                        logger.info("监事会对比一致");
                        jshComponentResult.setPromptMessage("对比一致，".concat(jshDesc));
                        jshComponentResult.setAnnotationFlag(false);
                        consistentCount++;
                    }else{
                        logger.info("监事会对比不一致");
                        jshComponentResult.setPromptMessage("对比不一致，".concat(jshDesc));
                        inconformityCount++;
                    }
                    componentResults.add(jshComponentResult);
                }else if(m56Jsh==0 && m57Jsh!=0){
                    unidentification++;
                    jshComponentResult.setPromptMessage("未识别".concat(getChapterId()).concat("治理结构监事总人数，").concat("已识别").concat(m57ChapterId).concat("企业人员基本情况监事总人数：").concat(String.valueOf(m57Jsh)).concat("，建议人工核对"));
                    componentResults.add(jshComponentResult);
                }else if(m56Jsh!=0 && m57Jsh==0){
                    unidentification++;
                    jshComponentResult.setPromptMessage("未识别".concat(m57ChapterId).concat("企业人员基本情况监事总人数，").concat("已识别").concat(getChapterId()).concat("治理结构监事总人数：").concat(String.valueOf(m56Jsh)).concat("，建议人工核对"));
//                    List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
//                    ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
//                    if(jshKvTextValue!=null){
//                        TextLayout textLayout = jshKvTextValue.getTextLayout();
//                        if(textLayout!=null){
//                            textLayout.setLeft(textLayout.getLeft());
//                            textLayout.setTop(textLayout.getTop());
//                            textLayout.setText(textLayout.getText());
//                            textPositionList.add(textPosition);
//                            jshComponentResult.setPageNum(textLayout.getPageNumber());
//                        }
//                    }
//                    jshComponentResult.setTextPosition(textPositionList);
                    componentResults.add(jshComponentResult);
                }else if(m56Jsh==0 && m57Jsh==0){
                    unidentification++;
                    jshComponentResult.setPromptMessage("未识别".concat(getChapterId()).concat("治理结构监事总人数，").concat("未识别").concat(m57ChapterId).concat("企业人员基本情况监事总人数").concat("，建议人工核对"));
                    componentResults.add(jshComponentResult);
                }

                ComponentResult gjglComponentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),getChapterId().concat("治理结构高管总人数对比").concat(m57ChapterId).concat("企业人员基本情况高管总人数"),"",true,getRegulationId(),chapterModel.getStartPage(),null,"03");

                TextLayout gjglTextLayout = getTextLayout(extractItemList,"副总",true)!=null?getTextLayout(extractItemList,"副总",true):getSectionTitlePosition(sectionModelList,"高管");

                if(gjglTextLayout!=null){
                    List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                    ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                    textPosition.setX(gjglTextLayout.getLeft());
                    textPosition.setY(gjglTextLayout.getTop());
                    textPosition.setContent(gjglTextLayout.getText());
                    textPositionList.add(textPosition);
                    gjglComponentResult.setPageNum(gjglTextLayout.getPageNumber());
                    gjglComponentResult.setTextPosition(textPositionList);
                }

                if(m56GJgl!=0 && m57Gjgl!=0){
                    String gjglDesc = getChapterId().concat("治理结构高管总人数：").concat(String.valueOf(m56GJgl)).concat("，").concat(m57ChapterId).concat("企业人员基本情况高管总人数：").concat(String.valueOf(m57Gjgl));
                    logger.info("desc：{}",gjglDesc);
                    if(m56GJgl == m57Gjgl){
                        logger.info("高管人数对比一致");
                        gjglComponentResult.setPromptMessage("对比一致，".concat(gjglDesc));
                        gjglComponentResult.setAnnotationFlag(false);
                        consistentCount++;
                    }else{
                        logger.info("高管人数对比不一致");
                        gjglComponentResult.setPromptMessage("对比不一致，".concat(gjglDesc));
                        inconformityCount++;
                    }
                    componentResults.add(gjglComponentResult);
                }else if(m56GJgl==0 && m57Gjgl!=0){
                    unidentification++;
                    gjglComponentResult.setPromptMessage("未识别".concat(getChapterId()).concat("治理结构高管总人数，").concat("已识别").concat(m57ChapterId).concat("企业人员基本情况高管总人数：").concat(String.valueOf(m57Gjgl)).concat("，建议人工核对"));
                    componentResults.add(gjglComponentResult);
                }else if(m56GJgl!=0 && m57Gjgl==0){
                    unidentification++;
                    gjglComponentResult.setPromptMessage("未识别".concat(m57ChapterId).concat("企业人员基本情况高管总人数，").concat("已识别").concat(getChapterId()).concat("治理结构高管总人数：").concat(String.valueOf(m56GJgl)).concat("，建议人工核对"));
//                    List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
//                    ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
//                    if(gjglKvTextValue!=null){
//                        TextLayout textLayout = gjglKvTextValue.getTextLayout();
//                        if(textLayout!=null){
//                            gjglComponentResult.setPageNum(textLayout.getPageNumber());
//                            textLayout.setLeft(textLayout.getLeft());
//                            textLayout.setTop(textLayout.getTop());
//                            textLayout.setText(textLayout.getText());
//                            textPositionList.add(textPosition);
//                        }
//                    }
//                    gjglComponentResult.setTextPosition(textPositionList);
                    componentResults.add(gjglComponentResult);
                }else if(m56GJgl==0 && m57Gjgl==0){
                    unidentification++;
                    gjglComponentResult.setPromptMessage("未识别".concat(getChapterId()).concat("治理结构高管总人数，").concat("未识别").concat(m57ChapterId).concat("企业人员基本情况高管总人数").concat("，建议人工核对"));
                    componentResults.add(gjglComponentResult);
                }

                if(componentResults.size()>0){
                    if(inconformityCount>0){
                        for(ComponentResult _componentResult : componentResults) {
                            _componentResult.setExist("02");
                        }
                        return componentResults;
                    }else{
                        if(unidentification>0){
                            for(ComponentResult _componentResult : componentResults) {
                                _componentResult.setExist("03");
                            }
                            return componentResults;
                        }else{
                            if(consistentCount>0){
                                for(ComponentResult _componentResult : componentResults) {
                                    _componentResult.setAnnotationFlag(false);
                                    _componentResult.setExist("01");
                                }
                                return componentResults;
                            }
                        }
                    }
                }
            }else{
                componentResult.setPromptMessage("未识别".concat(getCatalogId()).concat("数据，建议人工核对"));
                componentResults.add(componentResult);
                return componentResults;
            }
        }catch (Exception e){
            logger.error(e.getMessage(),e);
            if(componentResults.size()==0){
                componentResult.setPromptMessage("未识别".concat(getCatalogId()).concat("数据，建议人工核对"));
                if(chapterModel!=null) componentResult.setPageNum(chapterModel.getStartPage());
                componentResults.add(componentResult);
                return componentResults;
            }
        }

        return componentResults;
    }

    private int getNumber(String text){
        Map<String,Integer> map = new HashMap<>();
        map.put("一",1);
        map.put("二",2);
        map.put("三",3);
        map.put("四",4);
        map.put("五",5);
        map.put("六",6);
        map.put("七",7);
        map.put("八",8);
        map.put("九",9);
        map.put("十",10);

        String regex = "\\d{1,}\\s{0,}[名{0,1}|人{0,1}]";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);

        if(matcher.matches()){
            regex = "\\d{1,}";
            pattern = Pattern.compile(regex);
            matcher = pattern.matcher(text);
            while(matcher.find()) {
                return Integer.parseInt(matcher.group(0));
            }
        }else{
            regex = "[一|二|三|四|五|六|七|八|九|十]{1,}\\s{0,}[名{0,1}|人{0,1}]";
            pattern = Pattern.compile(regex);
            matcher = pattern.matcher(text);
            if(matcher.matches()){
                regex = "[一|二|三|四|五|六|七|八|九|十]{1,}";
                pattern = Pattern.compile(regex);
                matcher = pattern.matcher(text);
                String count = null;
                while(matcher.find()) {
                    count = matcher.group(0);
                }

                if(StringUtils.isNotEmpty(count)){
                    if(count.length()==2){
                        //十位
                        String tenthDigit = count.substring(0,1);
                        logger.info("十位：{}",tenthDigit);
                        BigDecimal tenthDecimal = new BigDecimal(map.get(tenthDigit)).multiply(BigDecimal.TEN);

                        //个位
                        String bits = count.substring(1);
                        logger.info("个位：{}",bits);
                        BigDecimal bitsDecimal = new BigDecimal(map.get(bits));

                        BigDecimal number = tenthDecimal.add(bitsDecimal);
                        logger.info("原值：{}，数字转换后：{}",count,number.stripTrailingZeros().toPlainString());

                        return number.intValue();
                    }else if(count.length()==1){
                        return map.get(count);
                    }
                }
            }
        }

        return 0;
    }
}
